<?php
namespace app\admin\controller;

use app\admin\service\AdminService;
use think\captcha\Captcha;

/**
 * Class Login
 * @author Ralph
 * @package app\admin\controller
 */
class Login extends Base
{
    public function initialize()
    {
    }
    
    /**
     * 登录功能/页面
     * @return mixed|\think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function index()
    {
        if(request()->isPost()){
            $data = input('post.');
            $adminService = new AdminService();
            $res = $adminService->login($data);
            return ['code' => $res['code'], 'msg' => $res['msg'], 'url' => url('Index/index')];
        }
        return $this->fetch();
    }


    public function verify()
    {
        $config =    [
            // 验证码字体大小
            'fontSize'    =>    25,
            // 验证码位数
            'length'      =>    4,
            // 关闭验证码杂点
            'useNoise'    =>    false,
            'bg'          =>    [255,255,255],
        ];
        $captcha = new Captcha($config);
        return $captcha->entry();
    }

    /**
     * 注册
     */
    public function register()
    {

    }

    /**
     * 忘记密码
     */
    public function forgetPassword()
    {

    }
}
